package Z11_4_synchronizedControl;

import java.util.concurrent.locks.LockSupport;

/**
 * @author： pang-yun
 * @date： 2021-11-05 15:05
 * 功能目的 ：用于
 */

public class OrderControlParkUnpark {
        static Thread t1 ;
        static Thread t2 ;
        static Thread t3 ;

    public static void main(String[] args) {
        ParkUnpark parkUnpark = new ParkUnpark();
        t1= new Thread(()->{
            parkUnpark.print(t2,"a");
        });

        t2= new Thread(()->{
            parkUnpark.print(t3,"a");
        });

        t3= new Thread(()->{
            parkUnpark.print(t1,"a");
        });
        t1.start();
        t2.start();
        t3.start();

        LockSupport.unpark(t1);
    }
}

class ParkUnpark {
    private int loopNumber = 5;

    public void print(Thread thread, String s) {
        for (int i = 0; i < loopNumber; i++) {
            LockSupport.park();
            System.out.print(s);
            LockSupport.unpark(thread);
        }
    }
}